package com.xinqi.xinqidev.publisher.consumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xin麒
 * @date 2023/11/19 18:02
 */
@Configuration
public class FanoutConfiguration {

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("xinqiya.fanout");
    }

    @Bean
    public Queue fanoutQueue1() {
        return new Queue("xinqiyaFanout.queue1");
    }

    @Bean
    public Queue fanoutQueue2() {
        // QueueBuilder.durable("ff").build();//如果使用builder模式，那么要选择持久的// https://www.bilibili.com/video/BV1mN4y1Z7t9/?p=13
        return new Queue("xinqiyaFanout.queue2");
    }


    @Bean
    public Binding fanoutBinding1(FanoutExchange fanoutExchange,Queue fanoutQueue1) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding fanoutBinding2() {
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }

}
